nexus\api\event/arc.rs
1//! [ArcDPS EVTC](https://deltaconnected.com/arcdps/) bridge events.
2
3use super::Event;
4use arcdps::evtc::{self, Agent};
5use std::ffi::{c_char, CStr};
6
7/// ArcDPS EVTC combat local event.
8pub const COMBAT_LOCAL: Event<CombatData> =
9 unsafe { Event::new("EV_ARCDPS_COMBATEVENT_LOCAL_RAW") };
10
11/// ArcDPS EVTC combat squad event.
12pub const COMBAT_SQUAD: Event<CombatData> =
13 unsafe { Event::new("EV_ARCDPS_COMBATEVENT_SQUAD_RAW") };
14
15/// ArcDPS self join event.
16///
17/// Payload is [`AgentUpdate`] of the self player agent.
18///
19/// Events of this type are triggered upon map load.
20/// The last event can be retriggered on demand by addons sending an [`REPLAY_SELF_JOIN`] event.
21pub const SELF_JOIN: Event<AgentUpdate> = unsafe { Event::new("EV_ARCDPS_SELF_JOIN") };
22
23/// Replays the last [`SELF_JOIN`] event.
24pub const REPLAY_SELF_JOIN: Event<()> = unsafe { Event::new("EV_REPLAY_ARCDPS_SELF_JOIN") };
25
26/// ArcDPS self leave event.
27///
28/// Payload is [`AgentUpdate`] of the self player agent.
29///
30/// Events of this type are triggered when changing instance or leaving a party / squad.
31pub const SELF_LEAVE: Event<AgentUpdate> = unsafe { Event::new("EV_ARCDPS_SELF_LEAVE") };
32
33/// ArcDPS squad join event.
34///
35/// Payload is [`AgentUpdate`] of an allied player agent.
36/// Events of this type are triggered when allied players in your instance join your party/squad or when allied players in your party/squad join your instance.
37/// These events have a 2 second delay.
38///
39/// Nexus tracks all players in your squad and can retrigger these events on demand by addons sending an [`REPLAY_SQUAD_JOIN`] event.
40/// This is intended to be used during addon load, you should be careful to handle duplicates since this can be triggered by other addons.
41pub const SQUAD_JOIN: Event<AgentUpdate> = unsafe { Event::new("EV_ARCDPS_SQUAD_JOIN") };
42
43/// Replays [`SQUAD_JOIN`] events for the current squad.
44pub const REPLAY_SQUAD_JOIN: Event<()> = unsafe { Event::new("EV_REPLAY_ARCDPS_SQUAD_JOIN") };
45
46/// ArcDPS squad leave event.
47///
48/// Payload is [`AgentUpdate`] of an allied player agent.
49///
50/// Events of this type are triggered when allied players in your instance and party/squad either leave your instance or leave your party/squad.
51/// You will not recieve these events if you are the one to change instance or leave the party/squad.
52/// These events have a 2 second delay.
53pub const SQUAD_LEAVE: Event<AgentUpdate> = unsafe { Event::new("EV_ARCDPS_SQUAD_LEAVE") };
54
55/// ArcDPS target changed event.
56///
57/// Events of this type are triggered when you target an agent.
58/// The last event can be retriggered on demand by addons sending an [`REPLAY_TARGET_CHAGNED`] event.
59pub const TARGET_CHANGED: Event<AgentUpdate> = unsafe { Event::new("EV_ARCDPS_TARGET_CHANGED") };
60
61/// Replays the [`TARGET_CHANGED`] event for the current target.
62pub const REPLAY_TARGET_CHANGED: Event<()> =
63 unsafe { Event::new("EV_REPLAY_ARCDPS_TARGET_CHANGED") };
64
65/// ArcDPS player account name.
66///
67/// Triggered on first map load.
68/// Can be triggered on demand by sending `"EV_REQUEST_ACCOUNT_NAME"`.
69pub const ACCOUNT_NAME: Event<c_char> = unsafe { Event::new("EV_ACCOUNT_NAME") };
70
71/// ArcDPS agent update.
72#[derive(Debug, Clone)]
73#[repr(C)]
74pub struct AgentUpdate {
75 /// Account name.
76 account: [c_char; 64],
77
78 /// Character name.
79 character: [c_char; 64],
80
81 /// ArcDPS id of the agent.
82 pub id: usize,
83
84 /// Instance id of the agent.
85 pub instance_id: usize,
86
87 /// Whether the agent has been added or removed.
88 added: u32,
89
90 /// Whether the agent is the new target.
91 target: u32,
92
93 /// Whether the agent is self.
94 is_self: u32,
95
96 /// Agent profession.
97 pub prof: u32,
98
99 /// Agent elite specialization.
100 pub elite: u32,
101
102 /// Agent team.
103 pub team: u16,
104
105 /// Agent subgroup.
106 pub subgroup: u16,
107}
108
109impl AgentUpdate {
110 /// Returns the account name (if present).
111 #[inline]
112 pub fn account(&self) -> &CStr {
113 unsafe { CStr::from_ptr(self.account.as_ptr()) }
114 }
115
116 /// Returns the character name.
117 #[inline]
118 pub fn character(&self) -> &CStr {
119 unsafe { CStr::from_ptr(self.character.as_ptr()) }
120 }
121
122 /// Whether the agent has been added or removed.
123 #[inline]
124 pub fn is_added(&self) -> bool {
125 self.added != 0
126 }
127
128 /// Whether the agent is the new target.
129 #[inline]
130 pub fn is_target(&self) -> bool {
131 self.target != 0
132 }
133
134 /// Whether the agent is self.
135 #[inline]
136 pub fn is_self(&self) -> bool {
137 self.is_self != 0
138 }
139}
140
141/// ArcDPS EVTC combat event data.
142#[derive(Debug, Clone)]
143#[repr(C)]
144pub struct CombatData {
145 event: *const evtc::Event,
146 src: *const Agent,
147 dst: *const Agent,
148 pub id: u64,
149 pub rev: u64,
150}
151
152impl CombatData {
153 #[inline]
154 pub fn as_tuple(
155 &self,
156 ) -> (
157 Option<&evtc::Event>,
158 Option<&Agent>,
159 Option<&Agent>,
160 u64,
161 u64,
162 ) {
163 (self.event(), self.src(), self.dst(), self.id, self.rev)
164 }
165
166 /// Returns a pointer to the [`Event`].
167 #[inline]
168 pub fn event_ptr(&self) -> *const evtc::Event {
169 self.event
170 }
171
172 /// Returns the [`Event`].
173 #[inline]
174 pub fn event(&self) -> Option<&evtc::Event> {
175 unsafe { self.event.as_ref() }
176 }
177
178 /// Returns a pointer to the source [`Agent`].
179 #[inline]
180 pub fn src_ptr(&self) -> *const Agent {
181 self.src
182 }
183
184 /// Returns the [`Event`].
185 #[inline]
186 pub fn src(&self) -> Option<&Agent> {
187 unsafe { self.src.as_ref() }
188 }
189
190 /// Returns a pointer to the destination [`Agent`].
191 #[inline]
192 pub fn dst_ptr(&self) -> *const Agent {
193 self.dst
194 }
195
196 /// Returns the destination [`Agent`].
197 #[inline]
198 pub fn dst(&self) -> Option<&Agent> {
199 unsafe { self.dst.as_ref() }
200 }
201}